using System;
using System.Collections.Generic;
using System.Data;

using Elev.Core.DAL;
using Elev.Core.Utility;

namespace Elev.Core
{
    public class PeriodsFactory
    {
        public List<Period> GetPeriods()
        {
            PeriodInternal p = new PeriodInternal();
            DataTable dt = p.GetPeriods();
            List<Period> list = new List<Period>();

            if (dt.Rows.Count > 0)
                foreach (DataRow dr in dt.Rows)
                    list.Add(new Period(dr));

            return list;
        }

        public Period GetPeriod(int ID)
        {
            PeriodInternal p = new PeriodInternal();
            DataTable dt = p.GetPeriod(ID);

            if (dt.Rows.Count == 0)
                throw new ArgumentException(string.Format("There is no period for the id '{0}'", ID));

            if (dt.Rows.Count > 1)
                throw new ArgumentException(string.Format("There is more than one period for the id '{0}'", ID));

            return new Period(dt.Rows[0]);
        }
    }
}
